from django.db import models

from Contest.config import AuthType
from Person.models import Person
from Problems.models import Problem


# Create your models here.


class Contest(models.Model):
    title = models.CharField(max_length=100, null=False, blank=False)
    begin_time = models.DateTimeField()
    end_time = models.DateTimeField()
    description = models.TextField()
    auth_type = models.CharField(choices=AuthType.TYPE_CHOICES, max_length=20)
    creator = models.ForeignKey(to=Person, on_delete=models.CASCADE, null=False, blank=False)
    problems = models.ManyToManyField(to=Problem, related_name='contest_problems', blank=True)
    password = models.CharField(max_length=100, null=True, blank=True)
    participants = models.ManyToManyField(to=Person, related_name='contest_participants', blank=True)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='更新时间')
    is_delete = models.BooleanField(default=False, verbose_name='删除标记')

    class Meta:
        ordering = ['id']

    def __str__(self):
        return self.title
